package com.hunnyovo.springframework.beans.factory.support;

import com.hunnyovo.springframework.beans.factory.config.SingletonBeanRegistry;

import java.util.HashMap;
import java.util.Map;

/**
 * 默认单例bean接口实现
 *
 * @author Create By Cb
 * @date 2022/10/26 18:36
 **/
public class DefaultSingletonBeanRegistry implements SingletonBeanRegistry {

    private final Map<String, Object> singletonBeans = new HashMap<>();

    @Override
    public Object getSingleton(String beanName) {
        return this.singletonBeans.get(beanName);
    }

    /**
     * 添加单例bean
     *
     * @param beanName:
     * @param singletonBean:
     * @author Create By Cb
     * @date 2022/11/18 15:46
     */
    protected void addSingletonBean(String beanName, Object singletonBean) {
        this.singletonBeans.put(beanName, singletonBean);
    }

}
